#include<iostream>
#include<vector>
#include<sys/types.h>
#include<unistd.h>
using namespace std;

const int NUM = 10;

void SunProcess(int i)
{
  while(1)
  {
    cout << "子进程" << i << "的pid：" << getpid() << " ，ppid：" << getppid() << endl;
    sleep(10);
  }
}
int main()
{
  vector<int> vpid;
  cout << "父进程的pid：" << getpid() << endl;
  for(int i = 0 ; i < NUM ; i++)
  {
    int pid = fork();
    if(pid == 0)
    {
      SunProcess(i+1);
    }

    vpid.emplace_back(pid);
  }
  sleep(5);
  cout << "子进程的pid如下："<<endl;

  for(auto& e : vpid)
  {
    cout << " " << e << " ";
  }
  cout << endl;
  while(1)
  {

  }
  return 0;
}
